/**
 * Created by user on 2018/3/12.
 */
class MaterialVideoPlayer {
  id = 'materialVideo'
  lastTask = null
  play(url, seekTime, success, ended) {
    if (this.lastTask) {
      this.destroyLastTask()
    }
    this.lastTask = {
      success: success,
      ended: ended
    }
    var video = document.getElementById(this.id)
    video.src = url
    video.autoplay = false
    video.addEventListener('play', this.lastTask.success, false)
    video.addEventListener('ended', this.lastTask.ended, false)
    video.currentTime = seekTime
    video.play()
  }
  destroyLastTask() {
    var video = document.getElementById(this.id)
    video.pause()
    video.removeEventListener('play', this.lastTask.success, false)
    video.removeEventListener('ended', this.lastTask.ended, false)
  }
  stop() {
    if (this.lastTask) {
      this.destroyLastTask()
    }
  }
}
module.exports = new MaterialVideoPlayer()
